<?php 
    require_once("autoload.php");
	use Qiniu\Auth;
    use Qiniu\Processing\PersistentFop;
/* 
* 
* @desc URL安全形式的base64编码 
* @param string $str 
* @return string 
*/ 

function urlsafe_base64_encode($str){ 
$find = array("+","/"); 
$replace = array("-", "_"); 
return str_replace($find, $replace, base64_encode($str)); 
} 

/**

 *将音频格式转码成amr格式

 */

function dataTransfer($uniqid) {
	$auth = new Auth('TAf3CDD_Znu9W2WnpH9TGNniQo3QGToQUtyiRvUu', 'kxMmt8ilS4NG7k-J6Ah7jSK1GQci-2upUZM9VJZS');
	$bucket = 'sichuangyi';
	$pipeline = 'demopp';
	$savekey = urlsafe_base64_encode($bucket.":".$uniqid);
	$pfop = New PersistentFop($auth, $bucket,$pipeline,NULL,ture);
	$fops='avthumb/mp3/ab/128k/ar/44100/acodec/libmp3lame|saveas/'.$savekey;
	list($id, $err) = $pfop->execute($uniqid, $fops);
	if ($err != null) {
		return 0;
	} else {
		return 1;
	}
}

$uniqid = $_POST['uniqid'];
if($uniqid){
	if(dataTransfer($uniqid)){
		$mp3url = 'https://blhd.1demo.com/'.$uniqid.'?avinfo';
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $mp3url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		$json = curl_exec($ch);
		$json = json_decode($json);
		curl_close($ch);
		return intval($json->streams[0]->duration);
	}
}
return 0;
?>